<!--
~ Copyright 2018-present Open Networking Foundation
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~     http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<div id="ov-meter">
    <onos-loading [theme]="'light'" [running]="loadingIconShown"></onos-loading>
    <div class="tabular-header">
        <h2> Meter for Device {{id}} ({{tableData.length}} Total )</h2>

        <div class="ctrl-btns">
            <div class="refresh" (click)="toggleRefresh()">
                <!-- See icon.theme.css for the defintions of the classes active and refresh-->
                <onos-icon classes="{{ autoRefresh?'active refresh':'refresh' }}" iconId="refresh" iconSize="42" toolTip="{{ autoRefreshTip }}"></onos-icon>
            </div>
            <div class="separator"></div>
            <div routerLink="/device" [queryParams]="{ devId: id }" routerLinkActive="active">
                <onos-icon classes="{{ id ? 'active-rect':undefined }}" iconId="deviceTable" iconSize="42" toolTip="{{deviceTip}}"></onos-icon>
            </div>
            <div routerLink="/flow" [queryParams]="{ devId: id }" routerLinkActive="active">
                <onos-icon classes="{{ id ? 'active-rect' :undefined}}" iconId="flowTable" iconSize="42" toolTip="{{ flowTip }}"></onos-icon>
            </div>
            <div routerLink="/port" [queryParams]="{ devId: id }" routerLinkActive="active">
                <onos-icon classes="{{ id ? 'active-rect' :undefined}}" iconId="portTable" iconSize="42" toolTip="{{ portTip }}"></onos-icon>
            </div>
            <div routerLink="/group" [queryParams]="{ devId: id }" routerLinkActive="active">
                <onos-icon classes="{{ id ? 'active-rect' :undefined}}" iconId="groupTable" iconSize="42" toolTip="{{ groupTip }}"></onos-icon>
            </div>
            <div>
                <onos-icon classes="{{ id ? 'current-view' :undefined}}" iconId="meterTable" iconSize="42"></onos-icon>
            </div>
            <div routerLink="/pipeconf" [queryParams]="{ devId: id }" routerLinkActive="active">
                <onos-icon classes="{{ id ? 'active-rect' :undefined}}" iconId="pipeconfTable" iconSize="42" toolTip="{{ pipeconfTip }}"></onos-icon>
            </div>
        </div>

        <div class="search">
            <input id="searchinput" [(ngModel)]="tableDataFilter.queryStr" type="search" #search placeholder="Search" />
            <select [(ngModel)]="tableDataFilter.queryBy">
                <option value="" disabled>Search By</option>
                <option value="$">All Fields</option>
                <option value="id">Meter ID</option>
                <option value="app_id">App ID</option>
                <option value="state">State</option>
            </select>
        </div>
    </div>
    <div class="summary-list" onosTableResize>
        <div class="table-header">
            <table>
                <tr>
                    <td colId="id" (click)="onSort('id')">Meter ID
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('id')"></onos-icon>
                    </td>
                    <td colId="app_id" (click)="onSort('app_id')">App ID
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('app_id')"></onos-icon>
                    </td>
                    <td colId="state" (click)="onSort('state')">State
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('state')"></onos-icon>
                    </td>
                    <td colId="packets" (click)="onSort('packets')">Packets
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('packets')"></onos-icon>
                    </td>
                    <td colId="bytes" (click)="onSort('bytes')">
                        Bytes
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('bytes')"></onos-icon>
                    </td>
                </tr>
            </table>
        </div>

        <div class="table-body">
            <table>
                <tr class="table-body" *ngIf="tableData.length === 0" class="no-data">
                    <td colspan="5">{{annots.noRowsMsg}}</td>
                </tr>
                <ng-template ngFor let-meter [ngForOf]="tableData | filter : tableDataFilter">
                    <tr (click)="selectCallback($event, meter)" [ngClass]="{selected: meter.id === selId, 'data-change': isChanged(meter.id)}">
                        <td>{{meter.id}}</td>
                        <td>{{meter.app_id}}</td>
                        <td>{{meter.state}}</td>
                        <td>{{meter.packets}}</td>
                        <td>{{meter.bytes}}</td>
                    </tr>
                    <tr>
                        <td class="bands" colspan="5" [innerHTML]="meter.bands"></td>
                    </tr>
                </ng-template>
            </table>
        </div>
    </div>
</div>
